package com.fmdj.customer.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.fmdj.common.util.CommonResult;
import com.fmdj.customer.controller.form.CustomerCarEntity;
import com.fmdj.customer.controller.form.DeleteCustomerCarByIdForm;
import com.fmdj.customer.controller.form.SelectCustomerCarListForm;
import com.fmdj.customer.feign.CstServiceApi;
import com.fmdj.customer.service.CustomerCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;

@Service
public class CustomerCarServiceImpl implements CustomerCarService {

    @Autowired
    private CstServiceApi cstServiceApi;

    @Override
    @Transactional
    @LcnTransaction
    public int insert(CustomerCarEntity entity) {
        CommonResult commonResult = cstServiceApi.insert(entity);
        return (int)commonResult.get(CommonResult.RETURN_ROW);
    }

    @Override
    public ArrayList<HashMap> selectCarList(SelectCustomerCarListForm form) {
        CommonResult commonResult = cstServiceApi.selectCustomerCarList(form);
        ArrayList<HashMap> list = (ArrayList<HashMap>) commonResult.get(CommonResult.RETURN_RESULT);
        return list;
    }

    @Override
    @Transactional
    @LcnTransaction
    public int deleteCustomerCarById(DeleteCustomerCarByIdForm form) {
        CommonResult commonResult = cstServiceApi.deleteCustomerCarById(form);
        int rows = (int) commonResult.get(CommonResult.RETURN_ROW);
        return rows;
    }
}
